package com.org.gsc.shuaxindemo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.view.ViewGroup;
import android.widget.Toast;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.util.ArrayList;
import java.util.List;
/**
 * Created by qundui on 2017/6/26.
 */

public class EasyRVTest extends Activity implements RecyclerArrayAdapter.OnLoadMoreListener,SwipeRefreshLayout.OnRefreshListener {
     private EasyRecyclerView mEasyRecyclerView;
    private RecyclerArrayAdapter mMyAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.easyrv);
        mEasyRecyclerView= (EasyRecyclerView) findViewById(R.id.rv);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        mEasyRecyclerView.setLayoutManager(linearLayoutManager);
        List<String> ttiles=new ArrayList<>();
        for(int i=0;i<30;i++){
            ttiles.add("第"+(i+1)+"条数据");
        }
        mMyAdapter = new RecyclerArrayAdapter<String>(this, ttiles) {
            @Override
            public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                return new MyViewHolder(parent);
            }
        };
        mEasyRecyclerView.setAdapterWithProgress(mMyAdapter);

        mMyAdapter.setMore(R.layout.more,this);
        mMyAdapter.setNoMore(R.layout.nomore);
        mEasyRecyclerView.setRefreshListener(this);


    }

    @Override
    public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mMyAdapter.clear();
                List<String> ttiles=new ArrayList<>();
                for(int i=0;i<20;i++){
                    ttiles.add("onRefresh()"+i+1);

                }
                mMyAdapter.addAll(ttiles);
                mMyAdapter.pauseMore();
            }
        },2000);
        Toast.makeText(this,"onRefresh()",Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onLoadMore() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                List<String> ttiles=new ArrayList<>();
                for(int i=0;i<20;i++){
                    ttiles.add("onLoadMore()"+i+1);

                }
                mMyAdapter.addAll(ttiles);
                mMyAdapter.pauseMore();

            }
        },2000);
        Toast.makeText(this,"onLoadMore()",Toast.LENGTH_SHORT).show();
    }
}
